package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.auth.login.annotation.NeedLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.user.UserSubscribe;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserCollectVo;
import com.atguigu.tingshu.vo.user.UserSubscribeVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;


    @GetMapping("/findUserSubscribePage/{pn}/{pz}")
    public Result findUserSubscribePage(@PathVariable(value = "pn") Long pn,
                                        @PathVariable(value = "pz") Long pz) {

//        return Result.build(null, ResultCodeEnum.LOGIN_AUTH);
        return Result.ok();
    }

    // Request URL: http://localhost:8500/api/user/userInfo/isSubscribe/1593
    @GetMapping("/isSubscribe/{albumId}")
    @Operation(summary = "判断用户是否关注该专辑")
    public Result isSubscribe(@PathVariable Long albumId){
        Boolean userSubscribe = userInfoService.isSubscribe(albumId);
        return Result.ok(userSubscribe);
    }

    // Request URL: http://localhost:8500/api/user/userInfo/collect/51951
    @GetMapping("/collect/{trackId}")
    @Operation(summary = "用户点击收藏声音按钮")
    @NeedLogin
    public Result collect(@PathVariable Long trackId){
        Boolean result = userInfoService.collect(trackId);
        return Result.ok(result);
    }

    // Request URL: http://localhost:8500/api/user/userInfo/isCollect/51951
    @GetMapping("/isCollect/{trackId}")
    @Operation(summary = "判断用户是否收藏该声音")
    @NeedLogin
    public Result isCollect(@PathVariable Long trackId){
        Boolean result = userInfoService.isCollect(trackId);
        return Result.ok(result);
    }

    // Request URL: http://localhost:8500/api/user/userInfo/findUserCollectPage/1/10
    @GetMapping("/findUserCollectPage/{pn}/{pz}")
    @Operation(summary = "分页查询用户收藏的专辑")
    @NeedLogin
    public Result findUserCollectPage(@PathVariable Long pn,
                                      @PathVariable Long pz){
        IPage<UserCollectVo> page = new Page<>(pn,pz);
        page = userInfoService.findUserCollectPage(page);
        return Result.ok(page);
    }


}

